<!doctype html>
[#escape x as (x)!?html]
<html lang="zh-CN">
<head>
  <meta charset="utf-8" />
  <title>密码重置 - ${site.seoTitle} - Powered by JPROCMS</title>
  [#include '../includes/common_res.html'/]
  <link rel="stylesheet" href="${resource}/static/plugins/aj-captcha/css/verify.css">
  <script src="${resource}/static/plugins/crypto-js/crypto-js.min.js"></script>
  <script src="${resource}/static/plugins/sm-crypto/dist/sm2.js"></script>
  <script src="${resource}/static/plugins/aj-captcha/js/crypto-js.js"></script>
  <script src="${resource}/static/plugins/aj-captcha/js/ase.js"></script>
  <script src="${resource}/static/plugins/aj-captcha/js/verify.js"></script>
</head>
<body class="bg-light">
<div class="container my-3 my-md-4 my-lg-5">
  <div class="row justify-content-center">
    <div class="col col-md-6 col-lg-5 col-xl-5 reg-box">
      <h3 class="reg-logo text-center">
        <a href="/"><b>JPROCMS</b></a> <span>重置密码</span>
      </h3>
      <div class="reg-box-body rounded p-4 mt-4" style="background-color:#fff;border:1px solid #ccc;">
        <ul class="nav nav-pills small">
          <li class="nav-item">
            <a id="mobileTab" class="nav-link active" href="javascript:"
               onclick="$('#mobileTab').addClass('active');$('#emailTab').removeClass('active');$('.mobileField').removeClass('d-none');$('.emailField').addClass('d-none');">手机号码</a>
          </li>
          <li class="nav-item">
            <a id="emailTab" class="nav-link" href="javascript:"
               onclick="$('#emailTab').addClass('active');$('#mobileTab').removeClass('active');$('.emailField').removeClass('d-none');$('.mobileField').addClass('d-none');">邮箱地址</a>
          </li>
        </ul>
        <form class="my-2" id="validForm" action="${api}/user/reset-password" method="post">
          <div class="form-group mobileField">
            <label class="sr-only" for="mobile">手机号码</label>
            <input type="text" class="form-control" id="mobile" name="mobile" placeholder="手机号码" autocomplete="off" required title="请填写手机号码"
                   data-rule-pattern="^1\d{10}$" data-msg-pattern="请填写有效的手机号码" data-rule-remote="${api}/user/mobileExist" data-msg-remote="手机号码不存在">
          </div>
          <div class="form-group mobileField">
            <label class="sr-only" for="mobileCode">短信验证码</label>
            <div class="input-group">
              <input type="text" class="form-control" id="mobileCode" name="mobileCode" placeholder="短信验证码" autocomplete="off" required title="请填写短信验证码"
                     data-msg-remote="短信验证码不正确">
              <span class="input-group-append"><button class="btn btn-secondary" id="mobileMessageButton" type="button">获取短信验证码</button></span>
            </div>
          </div>

          <div class="form-group d-none emailField">
            <label class="sr-only" for="email">邮箱地址</label>
            <input type="text" class="form-control" id="email" name="email" placeholder="邮箱地址" autocomplete="off" required title="请填写邮箱地址"
                   data-rule-email="true" data-msg-email="请填写有效的邮箱地址" data-rule-remote="${api}/user/emailExist" data-msg-remote="邮箱地址不存在">
          </div>
          <div class="form-group d-none emailField">
            <label class="sr-only" for="emailCode">邮件验证码</label>
            <div class="input-group">
              <input type="text" class="form-control" id="emailCode" name="emailCode" placeholder="邮件验证码" autocomplete="off" required title="请填写邮件验证码"
                     data-msg-remote="邮件验证码不正确">
              <span class="input-group-append"><button class="btn btn-secondary" id="emailMessageButton" type="button">获取邮件验证码</button></span>
            </div>
          </div>

          <div class="form-group">
            <label class="sr-only" for="password">新密码</label>
            [#if config.securityConfig.passwordStrength == 1]
              [#assign dataMsgPattern='密码中必须包含字母、数字']
            [#elseif config.securityConfig.passwordStrength == 2]
              [#assign dataMsgPattern='密码中必须包含大写字母、小写字母、数字']
            [#elseif config.securityConfig.passwordStrength == 3]
              [#assign dataMsgPattern='密码中必须包含字母、数字、特殊字符']
            [#elseif config.securityConfig.passwordStrength == 4]
              [#assign dataMsgPattern='密码中必须包含大写字母、小写字母、数字、特殊字符']
            [#else]
              [#assign dataMsgPattern='密码可以是任意字符']
            [/#if]
            <input type="password" class="form-control" id="password" name="password" placeholder="密码" autocomplete="off" title="请输入密码" required
            maxlength="${config.securityConfig.passwordMaxLength}"
            data-rule-minlength="${config.securityConfig.passwordMinLength}" data-msg-minlength="密码不能少于 ${config.securityConfig.passwordMinLength} 个字符"
            data-rule-pattern="${config.securityConfig.passwordPattern}" data-msg-pattern="${dataMsgPattern}">
          </div>
          <div class="form-group">
            <label class="sr-only" for="confirmPassword">确认密码</label>
            <input type="password" class="form-control" id="confirmPassword" placeholder="确认密码" autocomplete="off" title="请确认密码" required
                   data-rule-equalTo="#password" data-msg-equalTo="两次输入不相同">
          </div>

          <button type="submit" class="btn btn-primary btn-block">提交</button>
        </form>
      </div>
    </div>
  </div>
</div>
[#include '../includes/inc_msg.html'/]
[#include '../includes/inc_valid_msg.html'/]
<script>
  var publicKey='';
  axios.get('${api}/user/get-client-public-key',{headers: {'Tenant-Id': Cms.getTenantId()}}).then(function (response) {
    publicKey = response.data.data;
  });

  function sm2Encrypt(message) {
     // 1 - C1C3C2，0 - C1C2C3，默认为1
     const cipherMode = 1 
    let encryStr=sm2.doEncrypt(message, publicKey, cipherMode);
    return encryStr;
  }

  $(function () {
    $('#mobile').focus().select();
    var validator = $('#validForm').validate({
      submitHandler: function (form) {
        var body = $(form).serializeJSON();
        if (body.password) {
          body.password = sm2Encrypt(body.password);
        }
        request.post(form.action, body).then(function (response) {
          console.log(response.data);
          if (response.data.code == 0) {
              successShow();
              location.href = '${base}/login';
          } else {
              alertShow(response.data.msg)
          }
        });
      }
    });
    $('#emailMessageButton').click(function () {
      let email = $("#email").val();
      if (!Cms.isValidEmail(email)) {
        $("#email").focus()
        return
      }
      //场景3 忘记密码
      sendEmailMessage($('#email'), 3);
    });
    $('#mobileMessageButton').click(function () {
      let phoneNumber = $("#mobile").val();
      if (!Cms.isValidPhoneNumber(phoneNumber)) {
        $("#mobile").focus()
        return
      }
      //场景3 忘记密码
      sendMobileMessage( $('#mobile'), 3);
    });
  });

</script>
</body>
</html>
[/#escape]
